<template>
  <div class="user-role-add-dialog">
    <el-dialog :title="title" :visible.sync="visible" width="800px" v-drag-dialog append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="辅导员">
          <el-input v-model="form.fname" disabled></el-input>
        </el-form-item>

        <el-form-item label="">
          <el-input v-model="form.name"></el-input>
        </el-form-item>



        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
      {{form}}
    </el-dialog>
  </div>
</template>

<script>
import { getSession } from '@/utils/storage'
import { dragDialog } from "@/utils/directive"
export default {
  name: 'userRoleAddDialog',
  data() {
    return {
      visible: false,
      form: {
        fname: ''
      },
      //弹出框标题
      title:'新增菜单',
      superMenuData: [],
    }
  },
  created() {
    dragDialog()

  },
  mounted() {

  },
  methods: {
    //初始化表单

    initFrom() {
      this.form.fname=getSession('userInfo').finstructor.fname;
    },
    //表单提交
    onSubmit() {
      console.log('submit!');
    },
    // 打开弹窗
    open(row) {
      console.log(row)
      this.superMenuData = this.filterMenu(row)
      this.visible = true
      this.initFrom()
    },
    // 关闭弹窗
    close() {
      this.visible = false
    },
    // 取消
    onResetForm(formName) {
      this.$refs[formName].resetFields()
      this.close()
    },
    // 上级菜单改变
    onSuperMenuDataChange() {
      let ids = this.ruleForm.superMenuDataId
      if (ids.length > 0) {
        this.ruleForm.meta.parent = ids[0]
        this.ruleForm.parentPath = ids[ids.length - 1]
        this.ruleForm.meta.affix = false
      }
    },
    // 是否外链改变
    onExternalLinksChange() {
      this.ruleForm.meta.externalLinkType = this.ruleForm.meta.isExternalLinks ? 'opne' : ''
    },
    // 获取子组件当前点击值
    onSendIcon(icon) {
      this.ruleForm.meta.icon = icon
    },
    // 菜单格式处理
    filterMenu(arr) {
      return arr.map((item) => {
        item["title"] = item.meta.title;
        item = Object.assign({}, item);
        if (item.children) item.children = this.filterMenu(item.children)
        return item;
      });
    }
  }
}
</script>